// VBConversions Note: VB project level imports
using System.Collections.Generic;
using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Xml.Linq;
using Microsoft.VisualBasic.Compatibility;
using System.Windows.Forms;
using System.Collections;
using System.Data;
// End of VB project level imports

using System.Drawing.Drawing2D;


namespace 喷码数据生成工具
{
	public class gdButton : System.Windows.Forms.Button
	{
		public gdButton()
		{
			// VBConversions Note: Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
			mNormalColor = new Color[] {Color.FromArgb(255, 248, 214, 151), Color.FromArgb(255, 242, 197, 107), Color.FromArgb(255, 242, 197, 107), Color.FromArgb(255, 248, 214, 151)};
			mNormalBorder = Color.FromArgb(255, 242, 149, 54);
			mFocusColor = new Color[] {Color.FromArgb(255, 242, 149, 54), Color.FromArgb(255, 255, 252, 216), Color.FromArgb(255, 255, 235, 161), Color.FromArgb(255, 255, 213, 74), Color.FromArgb(255, 255, 234, 171)};
			mDownColor = new Color[] {Color.FromArgb(255, 245, 202, 154), Color.FromArgb(255, 251, 177, 106), Color.FromArgb(255, 249, 154, 54), Color.FromArgb(255, 253, 240, 175)};
			mDownBorder = Color.FromArgb(255, 142, 129, 101);
			mFocusBorder = Color.FromArgb(255, 192, 167, 118);
			mTextColor1 = Color.FromArgb(255, 120, 156, 35);
			mTextColor2 = Color.FromArgb(255, 51, 74, 33);
			mTextBorderColor = Color.FromArgb(200, 235, 231, 224);
			
		}
		bool DownEvent = false;
		bool Overg = false;
		bool OnFocus = false;
		bool onOver = false;
		// Private mNormalColor1 As Color=
		public delegate void UIChangeEventHandler(Bitmap Image);
		private UIChangeEventHandler UIChangeEvent;
		
		public event UIChangeEventHandler UIChange
		{
			add
			{
				UIChangeEvent = (UIChangeEventHandler) System.Delegate.Combine(UIChangeEvent, value);
			}
			remove
			{
				UIChangeEvent = (UIChangeEventHandler) System.Delegate.Remove(UIChangeEvent, value);
			}
		}
		
		bool mAttatchSkin = false;
		bool mTextByPath = false;
		private enum EnumMouseEvent
		{
			MouseLeave = 0,
			MouseMove = 1,
			MouseDown = 2
		}
		private enum buttonStyle
		{
			/// <summary>
			/// 正常为选中按钮
			/// </summary>
			ButtonNormal,
			/// <summary>
			/// 获得焦点的按钮
			/// </summary>
			ButtonFocuse,
			/// <summary>
			/// 鼠标经过样式
			/// </summary>
			ButtonMouseOver,
			/// <summary>
			/// 获得焦点并鼠标经过
			/// </summary>
			ButtonFocuseAndMouseOver,
			/// <summary>
			/// 鼠标按下事件
			/// </summary>
			ButtonMouseDown
		}
		private int mR = 3;
		//Public mNormalColor1 As Color = Color.FromArgb(255, 248, 214, 151)
		//Public mNormalColor2 As Color = Color.FromArgb(255, 242, 197, 107)
		//Public mNormalColor3 As Color = Color.FromArgb(255, 242, 197, 107)
		//Public mNormalColor4 As Color = Color.FromArgb(255, 248, 214, 151)
		private Color[] mNormalColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public Color mNormalBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		//Public mFocusColor1 As Color = Color.FromArgb(255, 255, 252, 216)
		//Public mFocusColor2 As Color = Color.FromArgb(255, 255, 235, 161)
		//Public mFocusColor3 As Color = Color.FromArgb(255, 255, 213, 74)
		//Public mFocusColor4 As Color = Color.FromArgb(255, 255, 234, 171)
		private Color[] mFocusColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		//Public mDownColor1 As Color = Color.FromArgb(255, 245, 202, 154)
		//Public mDownColor2 As Color = Color.FromArgb(255, 251, 177, 106)
		//Public mDownColor3 As Color = Color.FromArgb(255, 249, 154, 54)
		//Public mDownColor4 As Color = Color.FromArgb(255, 253, 240, 175)
		private Color[] mDownColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public Color mDownBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public Color mFocusBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public Color mTextColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public Color mTextColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public Color mTextBorderColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
#region 自定义属性
public int Radius
		{
			get
			{
				return mR;
			}
			set
			{
				if (mR > 0)
				{
					mR = value;
				}
				this.Refresh();
			}
		}
public Color TextColor1
		{
			get
			{
				return mTextColor1;
			}
			set
			{
				mTextColor1 = value;
				this.Refresh();
			}
		}
public Color TextColor2
		{
			get
			{
				return mTextColor2;
			}
			set
			{
				mTextColor2 = value;
				this.Refresh();
			}
		}
public Color TextBorderColor
		{
			get
			{
				return mTextBorderColor;
			}
			set
			{
				mTextBorderColor = value;
				this.Refresh();
			}
		}
public Color[] DownColor
		{
			get
			{
				return mDownColor;
			}
			set
			{
				mDownColor = value;
				this.Refresh();
			}
		}
public Color DownBorder
		{
			get
			{
				return mDownBorder;
			}
			set
			{
				mDownBorder = value;
				this.Refresh();
			}
		}
public Color FocusBorder
		{
			get
			{
				return mFocusBorder;
			}
			set
			{
				mFocusBorder = value;
				this.Refresh();
			}
		}
public Color[] FocusColor
		{
			get
			{
				return mFocusColor;
			}
			set
			{
				mFocusColor = value;
				this.Refresh();
			}
		}
public Color NormalBorder
		{
			get
			{
				return mNormalBorder;
			}
			set
			{
				mNormalBorder = value;
				this.Refresh();
			}
		}
		//Public Property NormalColor4() As Color
		//    Get
		//        Return mNormalColor4
		//    End Get
		//    Set(ByVal value As Color)
		//        mNormalColor4 = value
		//        Me.Refresh()
		//    End Set
		//End Property
		//Public Property NormalColor3() As Color
		//    Get
		//        Return mNormalColor3
		//    End Get
		//    Set(ByVal value As Color)
		//        mNormalColor3 = value
		//        Me.Refresh()
		//    End Set
		//End Property
		//Public Property NormalColor2() As Color
		//    Get
		//        Return mNormalColor2
		//    End Get
		//    Set(ByVal value As Color)
		//        mNormalColor2 = value
		//        Me.Refresh()
		//    End Set
		//End Property
public Color[] NormalColor
		{
			get
			{
				return mNormalColor;
			}
			set
			{
				mNormalColor = value;
				this.Refresh();
			}
		}
public bool AttachSkin
		{
			get
			{
				return mAttatchSkin;
			}
			set
			{
				mAttatchSkin = value;
				this.Refresh();
			}
		}
		/// <summary>
		/// 是否使用画刷绘制渐变文字
		/// </summary>
		/// <value></value>
		/// <returns></returns>
		/// <remarks></remarks>
public bool DrawTextByPath
		{
			get
			{
				return mTextByPath;
			}
			set
			{
				mTextByPath = value;
				this.Refresh();
			}
		}
#endregion
		protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent)
		{
			if (mAttatchSkin == true)
			{
				Graphics g = pevent.Graphics;
				
				Rectangle Bounds = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
				if (Bounds.Width <= 0 | Bounds.Height <= 0)
				{
					return ;
				}
				g.SmoothingMode = SmoothingMode.HighQuality;
				// g.Clear(Me.BackColor)
				try
				{
					if (onOver == true && DownEvent == false && OnFocus == false)
					{
						DrawButton(g, Bounds, buttonStyle.ButtonMouseOver);
					}
					else if (onOver == true && DownEvent == false && OnFocus == true)
					{
						DrawButton(g, Bounds, buttonStyle.ButtonFocuseAndMouseOver);
					}
					else if (onOver == true && DownEvent == true)
					{
						DrawButton(g, Bounds, buttonStyle.ButtonMouseDown);
					}
					else if (onOver == false && DownEvent == false && OnFocus == false)
					{
						DrawButton(g, Bounds, buttonStyle.ButtonNormal);
					}
					else if (onOver == false && DownEvent == false && OnFocus == true)
					{
						DrawButton(g, Bounds, buttonStyle.ButtonNormal);
					}
					else if (onOver == true && DownEvent == false && OnFocus == true)
					{
						DrawButton(g, Bounds, buttonStyle.ButtonFocuseAndMouseOver);
					}
					
				}
				catch (Exception)
				{
					//MsgBox(ex.Message)
				}
				
				return ;
			}
			base.OnPaint(pevent);
		}
		
		public void gdButton_Click(object sender, System.EventArgs e)
		{
			
		}
		
		public void gdButton_GotFocus(object sender, System.EventArgs e)
		{
			OnFocus = true;
		}
		
		public void gdButton_LostFocus(object sender, System.EventArgs e)
		{
			OnFocus = false;
		}
		
		public void gdButton_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			DownEvent = true;
			Overg = false;
		}
		
		public void gdButton_MouseLeave(object sender, System.EventArgs e)
		{
			DownEvent = false;
			Overg = false;
			onOver = false;
		}
		
		public void gdButton_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			onOver = true;
			Overg = true;
		}
		
		public void gdButton_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			DownEvent = false;
			Overg = false;
			if (mAttatchSkin == false)
			{
				return;
			}
			this.Refresh();
		}
		
		public void gdButton_Resize(object sender, System.EventArgs e)
		{
			if (this.Width > 0 & this.Height > 0)
			{
				Rectangle Bounds = new Rectangle(0, 0, this.Width, this.Height);
				GraphicsPath sPath = CreateRoundPath(Bounds, mR);
				this.Region = new Region(sPath);
				sPath.Dispose();
			}
		}
		private void DrawButton(Graphics g, Rectangle Bounds, buttonStyle BtnStyle)
		{
			//   Me.Parent.Text += "1"
			if (Bounds.Width <= 0 | Bounds.Height <= 0)
			{
				return;
			}
			g.SmoothingMode = SmoothingMode.HighQuality;
			Rectangle TopRect;
			Rectangle BottomRect;
			Color mBorderColor = new Color();
			TopRect = new Rectangle(Bounds.Location, new Size((int) Bounds.Width, (int) (Bounds.Height / 2)));
			BottomRect = new Rectangle((int) Bounds.Left, (int) (Bounds.Top + Bounds.Height / 2 - 1), (int) Bounds.Width, (int) (Bounds.Height / 2 + 1));
			g.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(0, 0, this.Width, this.Width));
			//==============设置画刷颜色
			Color[] BrushColor = null; //, BrushColor2 As Color, BrushColor3 As Color, BrushColor4 As Color
			if (BtnStyle == buttonStyle.ButtonFocuse | BtnStyle == buttonStyle.ButtonNormal)
			{
				// BrushColor1 = mNormalColor1 : BrushColor2 = mNormalColor2 : BrushColor3 = mNormalColor3 : BrushColor4 = mNormalColor4
				BrushColor = mNormalColor;
				mBorderColor = mNormalBorder;
			}
			else if (BtnStyle == buttonStyle.ButtonMouseOver)
			{
				BrushColor = mFocusColor;
				mBorderColor = mFocusBorder;
			}
			else if (BtnStyle == buttonStyle.ButtonFocuseAndMouseOver)
			{
				BrushColor = mFocusColor;
				mBorderColor = mFocusBorder;
			}
			else if (BtnStyle == buttonStyle.ButtonMouseDown)
			{
				BrushColor = mDownColor;
				mBorderColor = mDownBorder;
			}
			//==============设置画刷颜色
			//====================================绘制背景
			//Dim TopBrush As New LinearGradientBrush(TopRect, BrushColor1, BrushColor2, LinearGradientMode.Vertical)
			//Dim BottomBrush As New LinearGradientBrush(BottomRect, BrushColor3, BrushColor4, LinearGradientMode.Vertical)
			GraphicsPath BorderPath = CreateRoundPath(Bounds, mR);
			LinearGradientBrush DrawBrush = new LinearGradientBrush(Bounds, BrushColor[0], BrushColor[1], LinearGradientMode.Vertical);
			ColorBlend ColorBlends = default(ColorBlend);
			ColorBlends = CommFunction.getColorBlendByColors(BrushColor);
			DrawBrush.InterpolationColors = ColorBlends;
			// g.FillPath(TopBrush, TopPath)
			// g.FillPath(BottomBrush, BottomPath)
			g.FillPath(DrawBrush, BorderPath);
			//====================================绘制背景
			int Effect = 4;
			Rectangle FocusRect = new Rectangle((int) (Bounds.Left + Effect), (int) (Bounds.Top + Effect), (int) (Bounds.Width - Effect * 2), (int) (Bounds.Height - 2 * Effect));
			g.DrawPath(new Pen(mBorderColor, 1), BorderPath);
			if (OnFocus) //==========绘制焦点虚线
			{
				GraphicsPath FocusPath = CreateRoundPath(FocusRect, mR);
				Pen p = new Pen(mBorderColor, 0.5F);
				p.DashStyle = DashStyle.Dash;
				g.DrawPath(p, FocusPath);
				FocusPath.Dispose();
			}
			//==================================如有需显示背景图片显示图片
			if (!(this.Image == null))
			{
				switch (this.ImageAlign)
				{
					case ContentAlignment.TopLeft:
						g.DrawImage(this.Image, FocusRect, new Rectangle(0, 0, FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel);
						break;
					case ContentAlignment.TopCenter:
						g.DrawImage(this.Image, new Rectangle((int) ((Bounds.Width - this.Image.Width) / 2), FocusRect.Top, this.Image.Width, this.Image.Height), new Rectangle(0, 0, this.Image.Width, this.Image.Height), GraphicsUnit.Pixel);
						break;
					case ContentAlignment.TopRight:
						// Me.Parent.Text = "topright"
						g.DrawImage(this.Image, new Rectangle(FocusRect.Right - this.Image.Width, FocusRect.Top, this.Image.Width, this.Image.Height), new Rectangle(0, 0, this.Image.Width, this.Image.Width), GraphicsUnit.Pixel);
						break;
					case ContentAlignment.MiddleLeft:
						if (this.Image.Width <= FocusRect.Width & this.Image.Height <= FocusRect.Height)
						{
							g.DrawImage(this.Image, FocusRect.Left, Convert.ToInt32((Bounds.Height - this.Image.Height) / 2), this.Image.Width, this.Image.Height);
						}
						else
						{
							g.DrawImage(this.Image, new Rectangle(FocusRect.Left, FocusRect.Top, FocusRect.Width, FocusRect.Height), new Rectangle(0, FocusRect.Top - Convert.ToInt32((Bounds.Height - this.Image.Height) / 2), FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel);
						}
						break;
					case ContentAlignment.MiddleRight:
						if (this.Image.Width <= FocusRect.Width & this.Image.Height <= FocusRect.Height)
						{
							g.DrawImage(this.Image, FocusRect.Right - this.Image.Width, Convert.ToInt32((double) (FocusRect.Height - this.Image.Height) / 2), this.Image.Width, this.Image.Height);
						}
						else
						{
							g.DrawImage(this.Image, FocusRect, new Rectangle(this.Image.Width - FocusRect.Width, FocusRect.Top - Convert.ToInt32((Bounds.Height - this.Image.Height) / 2), FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel);
						}
						break;
					case ContentAlignment.MiddleCenter:
						if (this.Image.Width <= FocusRect.Width & this.Image.Height <= FocusRect.Height)
						{
							g.DrawImage(this.Image, Convert.ToInt32(FocusRect.Left + (double) (FocusRect.Width - this.Image.Width) / 2), (int) (FocusRect.Top + Convert.ToInt32((double) (FocusRect.Height - this.Image.Height) / 2)), this.Image.Width, this.Image.Height);
						}
						else
						{
							g.DrawImage(this.Image, FocusRect, FocusRect, GraphicsUnit.Pixel);
						}
						break;
					case ContentAlignment.BottomLeft:
						if (this.Image.Width <= FocusRect.Width & this.Image.Height <= FocusRect.Height)
						{
							g.DrawImage(this.Image, FocusRect.Left, FocusRect.Bottom - this.Image.Height, this.Image.Width, this.Image.Height);
						}
						else
						{
							g.DrawImage(this.Image, FocusRect, new Rectangle(0, this.Image.Height - FocusRect.Height, FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel);
						}
						break;
					case ContentAlignment.BottomCenter:
						if (this.Image.Width <= FocusRect.Width & this.Image.Height <= FocusRect.Height)
						{
							g.DrawImage(this.Image, Convert.ToInt32(FocusRect.Left + (double) (FocusRect.Width - this.Image.Width) / 2), FocusRect.Bottom - this.Image.Height, this.Image.Width, this.Image.Height);
						}
						else
						{
							g.DrawImage(this.Image, new Rectangle(Convert.ToInt32(FocusRect.Left + (double) (FocusRect.Width - this.Image.Width) / 2), FocusRect.Bottom - this.Image.Height, this.Image.Width, this.Image.Height), new Rectangle(Convert.ToInt32(FocusRect.Left + (double) (FocusRect.Width - this.Image.Width) / 2), FocusRect.Bottom - this.Image.Height, this.Image.Width, this.Image.Height), GraphicsUnit.Pixel);
							
						}
						break;
					case ContentAlignment.BottomRight:
						if (this.Image.Width <= FocusRect.Width & this.Image.Height <= FocusRect.Height)
						{
							g.DrawImage(this.Image, FocusRect.Right - this.Image.Width, FocusRect.Bottom - this.Image.Height, this.Image.Width, this.Image.Height);
						}
						else
						{
							g.DrawImage(this.Image, FocusRect, new Rectangle(this.Image.Width - FocusRect.Width, this.Image.Height - FocusRect.Height, FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel);
						}
						break;
				}
			}
			//==================================如有需显示背景图片显示图片
			//==================================绘制文本
			GraphicsPath TextPath = new GraphicsPath(FillMode.Alternate);
			SolidBrush TextBrush = new SolidBrush(this.ForeColor);
			StringFormat strFormat = default(StringFormat);
			Font TextFont = new Font(this.Font.Name, this.Font.Size, FontStyle.Regular);
			strFormat = new StringFormat();
			if (this.Enabled == false)
			{
				TextBrush = new SolidBrush(Color.FromArgb(150, 150, 150));
			}
			switch (TextAlign)
			{
				case ContentAlignment.TopLeft:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Near;
						strFormat.Alignment = StringAlignment.Near;
						TextPath.AddString(this.Text, new FontFamily(this.Font.Name), (System.Int32) this.Font.Style, this.Font.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(FocusRect.Location, Tsize.ToSize());
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Near;
						strFormat.Alignment = StringAlignment.Near;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.TopCenter:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Near;
						strFormat.Alignment = StringAlignment.Center;
						TextPath.AddString(this.Text, new FontFamily(this.Font.Name), (System.Int32) this.Font.Style, this.Font.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(FocusRect.Location, Tsize.ToSize());
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Near;
						strFormat.Alignment = StringAlignment.Center;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.TopRight:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Near;
						strFormat.Alignment = StringAlignment.Far;
						TextPath.AddString(this.Text, new FontFamily(this.Font.Name), (System.Int32) this.Font.Style, this.Font.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(FocusRect.Right - Tsize.Width, FocusRect.Top, (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Near;
						strFormat.Alignment = StringAlignment.Far;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.MiddleLeft:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Center;
						strFormat.Alignment = StringAlignment.Near;
						TextPath.AddString(this.Text, new FontFamily(TextFont.Name), (System.Int32) TextFont.Style, TextFont.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(FocusRect.Left, (int) (FocusRect.Top + Convert.ToInt32((FocusRect.Height - Tsize.Height) / 2)), (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Center;
						strFormat.Alignment = StringAlignment.Near;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.MiddleCenter:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Center;
						strFormat.Alignment = StringAlignment.Center;
						TextPath.AddString(this.Text, new FontFamily(TextFont.Name), (System.Int32) TextFont.Style, TextFont.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(FocusRect.Left + Convert.ToInt32((FocusRect.Width - Tsize.Width) / 2), (int) (FocusRect.Top + Convert.ToInt32((FocusRect.Height - Tsize.Height) / 2)), (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						try
						{
							strFormat.LineAlignment = StringAlignment.Center;
							strFormat.Alignment = StringAlignment.Center;
							g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
						}
						catch
						{
							this.Parent.Text = this.Text + "|" + TextFont.Name + "|" + TextBrush.ToString() + "|" + System.Convert.ToString(FocusRect.Width);
							if (TextFont == null)
							{
								this.Parent.Text = "textbrush disposed";
							}
						}
					}
					break;
				case ContentAlignment.MiddleRight:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Center;
						strFormat.Alignment = StringAlignment.Far;
						TextPath.AddString(this.Text, new FontFamily(TextFont.Name), (System.Int32) TextFont.Style, TextFont.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle((int) (FocusRect.Right - Tsize.Width), FocusRect.Top + Convert.ToInt32((FocusRect.Height - Tsize.Height) / 2), (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Center;
						strFormat.Alignment = StringAlignment.Far;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.BottomLeft:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Far;
						strFormat.Alignment = StringAlignment.Near;
						TextPath.AddString(this.Text, new FontFamily(TextFont.Name), (System.Int32) TextFont.Style, TextFont.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(FocusRect.Left, FocusRect.Bottom - Tsize.Height, (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Far;
						strFormat.Alignment = StringAlignment.Near;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.BottomCenter:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Far;
						strFormat.Alignment = StringAlignment.Center;
						TextPath.AddString(this.Text, new FontFamily(TextFont.Name), (System.Int32) TextFont.Style, TextFont.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle(Convert.ToInt32((FocusRect.Width - Tsize.Width) / 2) + FocusRect.Left, (int) (FocusRect.Bottom - Tsize.Height), (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Far;
						strFormat.Alignment = StringAlignment.Center;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
				case ContentAlignment.BottomRight:
					if (mTextByPath)
					{
						strFormat.LineAlignment = StringAlignment.Far;
						strFormat.Alignment = StringAlignment.Far;
						TextPath.AddString(this.Text, new FontFamily(TextFont.Name), (System.Int32) TextFont.Style, TextFont.Size, FocusRect, strFormat);
						SizeF Tsize = g.MeasureString(this.Text, TextFont);
						Rectangle DrawRect = new Rectangle((int) (FocusRect.Right - Tsize.Width), (int) (FocusRect.Bottom - Tsize.Height), (int) Tsize.Width, (int) Tsize.Height);
						LinearGradientBrush TBrush = new LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical);
						g.FillPath(TBrush, TextPath);
						g.DrawPath(new Pen(mTextBorderColor, 0.5F), TextPath);
					}
					else
					{
						strFormat.LineAlignment = StringAlignment.Far;
						strFormat.Alignment = StringAlignment.Far;
						g.DrawString(this.Text, TextFont, TextBrush, FocusRect, strFormat);
					}
					break;
			}
			strFormat.Dispose();
			TextPath.Dispose();
			//==================================绘制文本
			//TopPath.Dispose()
			//BottomPath.Dispose()
			BorderPath.Dispose();
			//TopBrush.Dispose()
			//BottomBrush.Dispose()
			
			if (UIChangeEvent != null)
				UIChangeEvent(null);
		}
		public object CreateRoundPath(Rectangle Rect, int R)
		{
			GraphicsPath ResultPath = new GraphicsPath(FillMode.Alternate);
			int L = 2 * R;
			Rectangle TmpRect = new Rectangle(RECT.Location, new Size(L, L));
			ResultPath.AddArc(TmpRect, 180.0F, 90.0F);
			ResultPath.AddLine(new Point((int) (Rect.Left + R), (int) Rect.Top), new Point(RECT.Right - R, (int) Rect.Top));
			TmpRect.X = RECT.Right - L;
			ResultPath.AddArc(TmpRect, 270.0F, 90.0F);
			ResultPath.AddLine(new Point(RECT.Right, (int) (Rect.Top + R)), new Point(RECT.Right, RECT.Bottom - R));
			TmpRect.Y = RECT.Bottom - L;
			ResultPath.AddArc(TmpRect, 0.0F, 90.0F);
			ResultPath.AddLine(new Point(RECT.Right - R, RECT.Bottom), new Point((int) (Rect.Left + R), RECT.Bottom));
			TmpRect.X = (int) Rect.Left;
			ResultPath.AddArc(TmpRect, 90.0F, 90.0F);
			ResultPath.AddLine(new Point((int) Rect.Left, RECT.Bottom - R), new Point((int) Rect.Left, (int) (Rect.Top + R)));
			return ResultPath;
		}
	}
	
	
}
